package com.bite.order.controller;
import com.bite.order.model.OrderInfo;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Random;
import java.util.UUID;

@RequestMapping("/order")
@RestController
public class OrderController {
    @Autowired
    private RabbitTemplate rabbitTemplate;
    @RequestMapping("/create")
    public String create() {
        //省略相关操作 例如校验参数 相关数据库操作
        //主要测试代码是否最后成功发送即可
        String orderId = UUID.randomUUID().toString();
        rabbitTemplate.convertAndSend("","order.create","下单成功, 订单 ID:"+orderId);
        return "下单成功！";
    }
    @RequestMapping("/create2")
    public String create2() {
        //省略相关操作 例如校验参数 相关数据库操作
        //主要测试代码是否最后成功发送即可
        OrderInfo orderInfo = new OrderInfo();
        orderInfo.setOrderId(UUID.randomUUID().toString());
        orderInfo.setName("商品："+new Random().nextInt(100));
        rabbitTemplate.convertAndSend("","order.create",orderInfo);
        return "下单成功！";
    }
}
